<template>
  <div id="container"></div>
</template>

<script setup>
import { onMounted, onUnmounted } from "vue";
import { Chart } from "@antv/g2";

let chart;

onMounted(() => {
  chart = new Chart({
    container,
    autoFit: true,
  });

  chart
    .title("零值折线图")
    .line()
    .data([
      { date: "06-10", count: 0, type: "测试" },
      { date: "06-11", count: 0, type: "测试" },
      { date: "06-12", count: 0, type: "测试" },
      { date: "06-13", count: 0, type: "测试" },
      { date: "06-14", count: 0, type: "测试" },
      { date: "06-15", count: 0, type: "测试" },
      { date: "06-16", count: 0, type: "测试" },
    ])
    .encode("x", "date")
    .encode("y", "count")
    .scale('y', {
        domain: [0, 1]
    })

  chart.render();
});

// 销毁
onUnmounted(() => {
  chart.destroy();
  chart = null;
});
</script>

<style lang="less" scoped>
#container {
  width: 800px;
  height: 400px;
}
</style>
